package com.yc.kernel.utils;

import ohos.app.Context;

import com.yc.kernel.factory.PlayerFactory;
import com.yc.kernel.impl.ijk.IjkPlayerFactory;
import com.yc.kernel.impl.media.MediaPlayerFactory;
import com.yc.kernel.inter.AbstractVideoPlayer;

/**
 * 工具类
 *
 * @since 2021-05-10
 */
public final class PlayerFactoryUtils {
    /**
     * 获取PlayerFactory具体实现类，获取内核
     * TYPE_NATIVE MediaPlayer，基于原生自带的播放器控件
     *
     * @param type 类型
     * @return return
     */
    public static PlayerFactory getPlayer(@PlayerConstant.PlayerType int type) {
        if (type == PlayerConstant.PlayerType.TYPE_EXO) {
            return MediaPlayerFactory.create();
        } else if (type == PlayerConstant.PlayerType.TYPE_IJK) {
            return IjkPlayerFactory.create();
        } else if (type == PlayerConstant.PlayerType.TYPE_NATIVE) {
            return MediaPlayerFactory.create();
        } else if (type == PlayerConstant.PlayerType.TYPE_RTC) {
            return IjkPlayerFactory.create();
        } else {
            return IjkPlayerFactory.create();
        }
    }

    /**
     * 获取PlayerFactory具体实现类，获取内核
     * 创建对象的时候只需要传递类型type，而不需要对应的工厂，即可创建具体的产品对象
     * TYPE_NATIVE MediaPlayer，基于原生自带的播放器控件
     *
     * @param context context
     * @param type 类型
     * @return return
     */
    public static AbstractVideoPlayer getVideoPlayer(Context context, @PlayerConstant.PlayerType int type) {
        if (type == PlayerConstant.PlayerType.TYPE_EXO) {
            return MediaPlayerFactory.create().createPlayer(context);
        } else if (type == PlayerConstant.PlayerType.TYPE_IJK) {
            return IjkPlayerFactory.create().createPlayer(context);
        } else if (type == PlayerConstant.PlayerType.TYPE_NATIVE) {
            return MediaPlayerFactory.create().createPlayer(context);
        } else if (type == PlayerConstant.PlayerType.TYPE_RTC) {
            return IjkPlayerFactory.create().createPlayer(context);
        } else {
            return IjkPlayerFactory.create().createPlayer(context);
        }
    }
}
